#include <wx/stdpaths.h>
#include "DBToolFrame.h"
#include "DBToolPanel.h"
#include "DBToolAbout.h"

BEGIN_EVENT_TABLE( DBToolFrame, MainFrame )
	EVT_MENU( ID_FILE_EXIT, DBToolFrame::OnExit )
	EVT_MENU( ID_FILE_OPEN, DBToolFrame::OnOpen )
	EVT_MENU( ID_HELP_ABOUT, DBToolFrame::OnAbout )
END_EVENT_TABLE()

DBToolFrame::DBToolFrame( wxWindow *parent, int id )
	: MainFrame( parent, id )
{
	wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );

	mainPanel = new DBToolPanel( this );
	sizer->Add( mainPanel, 1, wxEXPAND );
	wxSize panelSize = mainPanel->GetSize();
	this->SetSizerAndFit( sizer );
	this->SetClientSize( panelSize );	
}

void DBToolFrame::OnExit( wxCommandEvent& event )
{
	Close();
}

void DBToolFrame::OnOpen( wxCommandEvent& event )
{
	wxString caption = wxT("Choose a database file" );
	wxString wildcard = wxT("FusionSpy database files(*.db)|*.db");

	wxString defaultDir = wxStandardPaths::Get().GetDataDir();
	wxFileDialog dialog(this, caption, defaultDir, wxT(""),
		wildcard, wxOPEN );
	
	if( dialog.ShowModal() == wxID_OK )
	{
		wxString fileName = dialog.GetPath();
		strDatabaseFile = fileName;
		//strDatabaseFile->WriteText( fileName );
		mainPanel->SetDBFile( strDatabaseFile );
	}
}

void DBToolFrame::OnAbout( wxCommandEvent& event )
{
	DBToolAbout* about = new DBToolAbout( this );
	about->Show();
}

DBToolFrame::~DBToolFrame()
{
}